<?php 
session_start();
if (isset($_POST['name']) && isset($_SESSION['openid'])){
	$name=trim(addslashes($_POST['name']));
	$phone=trim(addslashes($_POST['phone']));
	$nianji=trim(addslashes($_POST['nianji']));
	$quyu=trim(addslashes($_POST['quyu']));
	
	include_once("../c/config.php");
	$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
	if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}
	$openid=$_SESSION['openid'];
	
	$sql="select id from u3 where name='".$name."' and phone='".$phone."' and nianji='".$nianji."' limit 0, 1";
	if ('nt' == $quyu){
	    $sql="select id from u3 where name='".$name."' and phone='".$phone."' and nianji='".$nianji."' and qu='南通分会场' limit 0, 1";
	}
	
	$query=$mysqli->query($sql);
    if($query->num_rows>0){
        $userInfo=$query->fetch_assoc();
        
        $query=$mysqli->query("select qu,xuexiao from u3 where id='".$userInfo['id']."'  limit 0, 1");
        $getUser=$query->fetch_assoc();
        
        
        
        $mysqli->query("update u3 set openid='".$openid."' where id='".$userInfo['id']."' ");
        
        echo json_encode(array('s'=>'ok','u'=>array('q'=>$getUser['qu'],'x'=>$getUser['xuexiao'])));
        exit;
    }
	 
	echo json_encode(array('s'=>'n'));
}else{
    echo json_encode(array('s'=>'n'));
}
?>